<header id="topbar">
    <div class="topbar-left">
        <ol class="breadcrumb">
            <li class="crumb-active">
                <a href="<%= window.location.href %>">每日用户数据</a>
            </li>
        </ol>
    </div>
</header>
<section id="content">
    <div class="panel">
        <form class="form-horizontal" role="form">
            <div class="form-group">
                <div class="col-md-10">
                    <input type="text" id="dateFilter" class="form-control text-center" value="<%= options.dateRange[0] %> ~ <%= options.dateRange[1] %>">
                </div>
                <% if(channels.length > 0){ %>
                    <div class="col-md-1">
                        <select id="chnFilter" class="from-control" multiple>
                            <% if(options.chn == null)options.chn = []; %>
                            <% _.each(channels, function(chn){ %>
                                <option value="<%= chn %>" <%= options.chn.indexOf(chn) == -1 ? "" : "selected" %>> <%= chn || "null" %> </option>
                            <% }) %>
                        </select>
                    </div>
                <% }else{ %>
                    <label for="search" class="col-md-1 control-label">无可选渠道数据</label>
                <% } %>
                <div class="col-md-1">
                    <input type="button" id="search" class="btn btn-primary btn-block form-control" value="提交">
                </div>
            </div>
        </form>
    </div>

    <div class="panel">
        <table class="table table-striped fs13" id="main-list">
            <thead>
                <tr class="bg-light">
                    <th class="sortable" data-field="_id">日期</th>
                    <th class="sortable" data-field="chn">渠道</th>
                    <th class="sortable" data-field="new_device">新增设备</th>
                    <th class="sortable" data-field="active_device">活跃设备</th>
                    <th class="sortable" data-field="new_register_device">注册设备数</th>
                    <th class="sortable" data-field="new_user">注册人数</th>
                    <th class="sortable" data-field="register_rate">帐号注册率</th>
                    <th class="sortable" data-field="stay_2_rate">设备次留</th>
                    <th class="sortable" data-field="user_stay_2_rate">帐号次留</th>
                    <th class="sortable" data-field="new_recharge_user">新增用户付费人数</th>
                    <th>新增付费设备</th>
                    <th class="sortable" data-field="new_recharge_rate">新增用户付费率</th>
                    <th class="sortable" data-field="new_recharge_price">新增用户付费金额</th>
                    <th class="sortable" data-field="active_user">活跃用户</th>
                    <th class="sortable" data-field="recharge_user">付费人数</th>
                    <th>付费设备</th>
                    <th class="sortable" data-field="recharge_rate">付费率</th>
                    <th class="sortable">活跃用户ARPU</th>
                </tr>
            </thead>
            <tbody class="admin-form">
                <% _.each(items, function(item){ %>
                    <tr>
                        <td><%= item.day || item._id %></td>
                        <td><%= item.chn || '-' %></td>
                        <td><%= item.new_device || 0 %></td>
                        <td><%= item.active_device || 0 %></td>
                        <td><%= item.new_register_device || 0 %></td>
                        <td><%= item.new_user || 0 %></td>
                        <td><%= ((item.register_rate || 0) * 100).toFixed(2) %>%</td>
                        <td><%= ((item.stay_2_rate || 0 ) * 100).toFixed(2) %>%</td>
                        <td><%= ((item.user_stay_2_rate || 0) * 100).toFixed(2) %>%</td>
                        <td><%= item.new_recharge_user || 0 %></td>
                        <td><%= item.new_recharge_device || 0 %></td>
                        <td><%= ((item.new_recharge_rate || 0) * 100).toFixed(2)  %>%</td>
                        <td><%= item.new_recharge_price || 0 %></td>
                        <td><%= item.active_user || 0 %></td>
                        <td><%= item.recharge_user || 0 %></td>
                        <td><%= item.recharge_device || 0 %></td>
                        <td><%= ((item.recharge_rate || 0) * 100).toFixed(2) %>%</td>
                        <%
                            if (item.active_user) {
                                var arpu_active = ((item.recharge_price || 0) / item.active_user).toFixed(2);
                            } else {
                                var arpu_active = 'null';
                            }
                        %>
                        <td><%= arpu_active %></td>
                    </tr>
                <% }) %>
            </tbody>
        </table>
    </div>
</section>
